package com.example.mpandroidchart1107;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;

import com.github.mikephil.charting.charts.BubbleChart;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.BubbleData;
import com.github.mikephil.charting.data.BubbleDataSet;
import com.github.mikephil.charting.data.BubbleEntry;
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
import java.util.ArrayList;
import java.util.List;

public class Main5Activity extends AppCompatActivity {

    private BubbleChart bubble;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main5);
        /*控制全屏显示*/
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setTitle("泡泡图");
        bubble = findViewById(R.id.bubble);/*第一步实例化*/

        float[] f1 ={1f,7f,4f,8f,3f,9f};
        float [] f2={9f,3f,7f,2f,5f,1f};
        float [] f3={2f,8f,4f,7f,3f,6f,};

        List<IBubbleDataSet> b = new ArrayList<>();//调用泡泡图的方法

        BubbleDataSet b1=getDataSet(f1,"人民币");
        b1.setColor(Color.parseColor("#FFDEAD"));
        b.add(b1);

        BubbleDataSet b2=getDataSet(f2,"美元");
        b2.setColor(Color.parseColor("#FFE4E1"));
        b.add(b2);

        BubbleDataSet b3=getDataSet(f3,"日元");
        b3.setColor(Color.parseColor("#B0E0E6"));
        b.add(b3);



        Description description = new Description();//更改右下角Description 显示内容
        description.setText("汇率泡泡图");
        description.setTextSize(12f);//字体大小
        bubble.setDescription(description);

        XAxis x=bubble.getXAxis();//控制x轴

        x.setPosition(XAxis.XAxisPosition.BOTTOM);
        x.setDrawAxisLine(false);

        BubbleData bubbleData=new BubbleData(b);
        bubble.setData(bubbleData);

        bubble.invalidate();

    }
    /*2.第二步*/
    private  BubbleDataSet getDataSet(float[]f,String title){

        List<BubbleEntry> data =new ArrayList<>();//Entry相当于坐标值
        for (int x =0; x<f.length;x++) {//遍历浮点数数组
            BubbleEntry bubbleEntry = new BubbleEntry(x, f[x],x);//x坐标y 坐标
            data.add(bubbleEntry);/*加入到点的集合中*/
        }
        return new BubbleDataSet(data,title);
    }

}

